package com.example.demo.Service.ServiceImp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.Mapper.UserMapper;
import com.example.demo.Service.UserService;
import com.example.demo.entity.User;
import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.swing.text.html.parser.Entity;
import java.util.HashMap;


//交给Spring 的容器进行管理
@Service
public class UseServiceImp implements UserService {

    @Resource
    private UserMapper userMapper;


    //业务层调用Mapper接口方法
    @Override
    public User login(User user) {

        User login = userMapper.selectOne(new QueryWrapper<User>().eq("username", user.getUsername()));

        BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
        boolean matches = passwordEncoder.matches(user.getPassword(), login.getPassword());

      return   matches==true? login:null;

    }
}
